//
//  Global.swift
//  Swift-Codedase
//
//  Created by 徐先生 on 2023/2/24.
//

import Foundation
import Localize_Swift

let xScreenW = UIScreen.main.bounds.width
let xScreenH = UIScreen.main.bounds.height

/// 是否iPhoneX系列
var xIsIphoneX: Bool {
    get {
        if xScreenW > 736 {
            return true
        } else {
            return false
        }
    }
}



// MARK: - print
func xLog<T>(_ message: T, file: String = #file, function: String = #function, lineNumber: Int = #line) {
#if DEBUG
    // 1.获取文件名,包含后缀名
    let name = (file as NSString).lastPathComponent
    // 1.1 切割文件名和后缀名
    let fileArray = name.split(separator: ".")
    // 1.2 获取文件名
    let fileName = fileArray[0]
    let dateformatter = DateFormatter()
    // dateformatter.dateFormat = "YYYY-MM-dd HH:mm:ss sss"
    dateformatter.dateFormat = "HH:mm:ss sss"
    let time = dateformatter.string(from: Date())
    // print("\(String(describing: time))-[\(fileName)_funciton:\(function)_line:\(lineNumber)]- \(message)")
    // print("\(String(describing: time)) \(fileName) [line:\(lineNumber)] \(message)")
    //↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
    //↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
    //------------------------------
    //------------------------------
    print("\n--------------Log-------------\n\(String(describing: time))\t\(fileName)\t[line:\(lineNumber)]\t\(function)\n\(message)\n------------------------------")
#endif
}


// MARK: - 本地化
/// 本地化文件名
enum LocalizedName: String {
    /// 登录
    case login = "LocalizableLogin"
    /// 首页
    case home = "LocalizableHome"
    /// 商城
    case store = "LocalizableStore"
    /// 视频通话
    case call = "LocalizableCall"
    /// 直播
    case live = "LocalizableLive"
    /// 翻译
    case tran = "LocalizableTranslator"
}

/// 本地化文件名使用扩展
extension String {
    
    func localized(_ name: LocalizedName) -> String {
        return localized(using: name.rawValue, in: .main)
    }
    
    func localizedFormat(arguments: CVarArg..., name: LocalizedName) -> String {
        return String(format: localized(name), arguments)
    }
}
